package 字符串;

public class pivotIndex {
    public int pivotIndex(int[] nums) {
        int n=nums.length;
        int sum=0,sumLeft=0,sumRight=0;
        for (int num:nums) sum+=num;
        int ans=-1;
        for (int i=0;i<n;++i){
            if(i-1>=0){
                sumLeft=sumLeft+nums[i-1];
            }
            sumRight=sum-sumLeft-nums[i];

            if(sumLeft==sumRight) return i;
        }

        return ans;


    }
}
